package com.codeczx.leanclouddemo;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.LogInCallback;

import java.io.IOException;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class SignUpActivity extends AppCompatActivity {

    private static final String TAG = "SignUpActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_up);
        signUp();
    }

    private void signUp() {
        AVUser.logInInBackground("codeczx", "123456", new LogInCallback<AVUser>() {
            @Override
            public void done(AVUser avUser, AVException e) {
                if(e==null){
                    Log.i(TAG, "done: avUser:"+avUser.getUsername());
                    doHttp();
                }else{
                    e.printStackTrace();
                }

            }
        });
    }

    private void doHttp(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                OkHttpClient okHttpClient = new OkHttpClient();
                Request request = new Request.Builder()
                        .url("http://api.zhixianshi.com/v2/roam/public?appBuild=20170605")
                        .build();
                Response response = null;
                try {
                    response = okHttpClient.newCall(request).execute();
                    Log.i(TAG, "doHttp: response:"+response.body().string());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
}
